package com.bdqn.crm.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import lombok.Data;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;


/**
 * 角色实体类
 */
@TableName ("sys_role")
@Data
public class Role implements Serializable {
    private static final long serialVersionUID = 42L;
    @TableId(value = "role_id",type = IdType.AUTO)
    @TableField("role_id")
    private Integer roleId;
    @TableField("role_name")
    private String roleName;
    @TableField("role_desc")
    private String roleDesc;
    @TableField("role_flag")
    private Integer roleFlag;
    @ManyToMany(targetEntity = Right.class,fetch = FetchType.LAZY)
    @JoinTable(name = "sys_role_right",
            joinColumns = {@JoinColumn(name = "rf_role_id",referencedColumnName = "rf_right_code")},
            inverseJoinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "role_id")}
    )
    private Set<Right> rights = new HashSet<>(0);
    //  @OneToMany(targetEntity = User.class,fetch = FetchType.EAGER,cascade = CascadeType.REMOVE,mappedBy = "role")
     private Set<User> users=new HashSet<>(0);

    public Role() {

    }

    public Role(String roleName, String roleDesc, Integer roleFlag) {
        this.roleName = roleName;
        this.roleDesc = roleDesc;
        this.roleFlag = roleFlag;
    }



}
